﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;

namespace Black.SurfaceToolkit.Effects
{
    /// <summary>
    /// ZoomBlurEffect Effect
    /// </summary>
    public class ZoomBlurEffect : ShaderEffect
    {
        #region Propriétées de dépendances

        public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(ZoomBlurEffect), 0);
        public static readonly DependencyProperty CenterProperty = DependencyProperty.Register("Center", typeof(Point), typeof(ZoomBlurEffect), new UIPropertyMetadata(new Point(0.5, 0.5), ShaderEffect.PixelShaderConstantCallback(0)));
        public static readonly DependencyProperty BlurAmountProperty = DependencyProperty.Register("BlurAmount", typeof(double), typeof(ZoomBlurEffect), new UIPropertyMetadata(0.0, ShaderEffect.PixelShaderConstantCallback(1)));

        #endregion

        #region Accesseurs

        /// <summary>
        /// Affecte ou retourne la propriété Input du Shader
        /// </summary>
        [System.ComponentModel.BrowsableAttribute(false)]
        public Brush Input
        {
            get
            {
                return ((Brush)this.GetValue(ZoomBlurEffect.InputProperty));
            }
            set
            {
                this.SetValue(ZoomBlurEffect.InputProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété BlurAmount du Shader
        /// </summary>
        public double BlurAmount
        {
            get
            {
                return ((double)this.GetValue(ZoomBlurEffect.BlurAmountProperty));
            }
            set
            {
                this.SetValue(ZoomBlurEffect.BlurAmountProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Center du Shader
        /// </summary>
        public Point Center
        {
            get
            {
                return ((Point)this.GetValue(ZoomBlurEffect.CenterProperty));
            }
            set
            {
                this.SetValue(ZoomBlurEffect.CenterProperty, value);
            }
        }

        #endregion

        #region Variables statiques

        private static readonly PixelShader _PixelShader = new PixelShader();

        #endregion

        #region Constructeurs

        /// <summary>
        /// Constructeur statique
        /// </summary>
        static ZoomBlurEffect()
        {
            ZoomBlurEffect._PixelShader.UriSource = new Uri("pack://application:,,,/Black.SurfaceToolkit;component/Effects/Shaders/ZoomBlur.ps");
        }

        /// <summary>
        /// Constructeur de la classe
        /// </summary>
        public ZoomBlurEffect()
        {
            this.PixelShader = ZoomBlurEffect._PixelShader;

            this.UpdateShaderValue(ZoomBlurEffect.InputProperty);
            this.UpdateShaderValue(ZoomBlurEffect.CenterProperty);
            this.UpdateShaderValue(ZoomBlurEffect.BlurAmountProperty);
        }

        #endregion
    }
}
